package com.wangjie.simple;

import java.util.Stack;

/**
 * @author jieshao
 * @date 2022/5/31 13:41
 *
 * 155. 最小栈
 */
public class MinStack {
    private Stack<Integer> s1;
    private Stack<Integer> s2;

    public MinStack() {
        this.s1 = new Stack<>();
        this.s2 = new Stack<>();
        s2.push(Integer.MAX_VALUE);
    }

    public void push(int val) {
        s1.push(val);
        s2.push(Math.min(val, s2.peek()));
    }

    public void pop() {
        s1.pop();
        s2.pop();
    }

    public int top() {
        return s1.peek();
    }

    public int getMin() {
        return s2.peek();
    }
}